package com.yunji.common.base.response;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/10/23 09:37
 * @description : TODO
 **/
public abstract class AbstractResponse<T> implements Response<T> {
    @ApiModelProperty(value = "返回代码")
    private int code;

    @ApiModelProperty(value = "返回消息")
    private String msg;

    @ApiModelProperty(value = "成功标志")
    @JsonIgnore
    private boolean success = true;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<Object> dataIds = Lists.newArrayList();

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public boolean isSuccess() {
        return success;
    }

    @Override
    public void setSuccess(boolean success) {
        this.success = success;
    }

    @Override
    public long getTime() {
        return System.currentTimeMillis();
    }

    @Override
    public Response<T> withDataIds(List<Object> dataIds) {
        this.dataIds = dataIds;
        return this;
    }

    @Override
    public Response<T> withDataId(Object dataId) {
        this.dataIds.add(dataId);
        return this;
    }
}
